<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="用户" prop="nickName">
        <el-input
          v-model="queryParams.nickName"
          placeholder="请输入用户"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="日期" prop="proDate">
        <el-date-picker clearable
          v-model="queryParams.proDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['sl:wagesday:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="wagesdayList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="用户" align="center" prop="nickName" />
      <el-table-column label="类型" align="center"  >
        <template slot-scope="scope">
          <span v-if="scope.row.workType=='0'">计件</span>
          <span v-else-if="scope.row.workType=='1'">零工</span>
        </template>
      </el-table-column>
      <el-table-column label="模块" align="center" prop="moduleName" />
      <el-table-column label="车间" align="center" prop="workshopName" />
      <el-table-column label="工序" align="center" prop="gprocessName" />
      <el-table-column label="出勤天数" align="center" prop="proDay" />
      <el-table-column label="结算天数" align="center" prop="proSettlement" />
      <el-table-column label="出勤工资" align="center" prop="proWages" />
      <el-table-column label="日期" align="center" prop="proDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.proDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="handleDetail(scope.row)"
            v-hasPermi="['sl:wagesday:query']"
          >详细</el-button>
          <!-- <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['sl:wagesday:remove']"
          >删除</el-button> -->
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改日工资对话框 -->
<!--    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="用户名" prop="userName">
          <el-input v-model="form.userName" placeholder="请输入用户名" />
        </el-form-item>
        <el-form-item label="用户昵称" prop="nickName">
          <el-input v-model="form.nickName" placeholder="请输入用户昵称" />
        </el-form-item>
        <el-form-item label="职级" prop="levelId">
          <el-input v-model="form.levelId" placeholder="请输入职级" />
        </el-form-item>
        <el-form-item label="计薪方式" prop="ssmId">
          <el-input v-model="form.ssmId" placeholder="请输入计薪方式" />
        </el-form-item>
        <el-form-item label="出勤天数" prop="proDay">
          <el-input v-model="form.proDay" placeholder="请输入出勤天数" />
        </el-form-item>
        <el-form-item label="结算天数" prop="proSettlement">
          <el-input v-model="form.proSettlement" placeholder="请输入结算天数" />
        </el-form-item>
        <el-form-item label="出勤工资" prop="proWages">
          <el-input v-model="form.proWages" placeholder="请输入出勤工资" />
        </el-form-item>
        <el-form-item label="日期" prop="proDate">
          <el-date-picker clearable
            v-model="form.proDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="报工单ID" prop="rfworkId">
          <el-input v-model="form.rfworkId" placeholder="请输入报工单ID" />
        </el-form-item>
        <el-form-item label="模块ID" prop="moduleId">
          <el-input v-model="form.moduleId" placeholder="请输入模块ID" />
        </el-form-item>
        <el-form-item label="车间" prop="workshopId">
          <el-input v-model="form.workshopId" placeholder="请输入车间" />
        </el-form-item>
        <el-form-item label="大工序" prop="gprocessId">
          <el-input v-model="form.gprocessId" placeholder="请输入大工序" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog> -->
  </div>
</template>

<script>
import { listWagesday, getWagesday, delWagesday, addWagesday, updateWagesday } from "@/api/sl/wagesday";

export default {
  name: "Wagesday",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 日工资表格数据
      wagesdayList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        userName: null,
        nickName: null,
        levelId: null,
        ssmId: null,
        proDay: null,
        proSettlement: null,
        proWages: null,
        proDate: null,
        rfworkId: null,
        moduleId: null,
        workshopId: null,
        gprocessId: null,
        workType: null,
        isYpk: null,
        rfworkssmId: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询日工资列表 */
    getList() {
      this.loading = true;
      listWagesday(this.queryParams).then(response => {
        this.wagesdayList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        wagesDayId: null,
        userName: null,
        nickName: null,
        levelId: null,
        ssmId: null,
        proDay: null,
        proSettlement: null,
        proWages: null,
        proDate: null,
        rfworkId: null,
        moduleId: null,
        workshopId: null,
        gprocessId: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        workType: null,
        isYpk: null,
        rfworkssmId: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.wagesDayId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 详细按钮操作 */
    handleDetail(row) {
      const bgType = row.workType;
      const rfworkId = row.rfworkId;
      const memberUser = row.userName;
      if(bgType==="0"){
        this.$router.push({ path: "/hrwork/hwork", query: {"rfworkId": rfworkId,"memberUser":memberUser} });
      }else if(bgType==="1"){
        this.$router.push({ path: "/hrwork/hoddjob", query: {"rfworkId": rfworkId,"memberUser":memberUser} });
      }

    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('sl/wagesday/export', {
        ...this.queryParams
      }, `wagesday_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
